package com.starview.platform.resource;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;

import com.starview.platform.data.value.ResourceURI;

public class HttpTransducer implements Transducer
{

  @Override
  public Reader getReader(ResourceURI uri) throws ResourceException
  {
    try {
      URL url = new URL(uri.toString());
      InputStream stream = url.openStream();
      return new InputStreamReader(stream);
    } catch (Exception e) {
      throw new ResourceException(e.getMessage());
    }
  }

  @Override
  public InputStream getInputStream(ResourceURI uri) throws ResourceException
  {
    try {
      URL url = new URL(uri.toString());
      return url.openStream();
    } catch (Exception e) {
      throw new ResourceException(e.getMessage());
    }
  }

  @Override
  public void putResource(ResourceURI uri, Object resource) throws ResourceException
  {
    throw new ResourceException("not implemented");
  }

  @Override
  public boolean exists(ResourceURI uri) throws ResourceException
  {
    throw new ResourceException("not implemented");
  }
}
